import os

BUILD_ID="0000000001"
CPPPATH="src/includes"
CFLAGS=[
    "-DXP_UNIX",
    "-DMOZ_X11",
    "-DMOZILLA_STRICT_API",
    "-fPIC",
    "-Wall",
    "-DBUILD_ID=%s" % BUILD_ID
]

env = Environment(CPPPATH=CPPPATH, CPPFLAGS=CFLAGS)

if os.environ.has_key("CXX"):
    CXX = os.environ["CXX"]
    env.Replace(CXX=CXX)

if os.environ.has_key("CFLAGS"):
    env.AppendUnique(CPPFLAGS=os.environ["CFLAGS"].split(' '))

def CheckPKGConfig(context, version):
     context.Message( 'Checking for pkg-config... ' )
     ret = context.TryAction('pkg-config --atleast-pkgconfig-version=%s' % version)[0]
     context.Result( ret )
     return ret

def CheckPKG(context, name):
     context.Message( 'Checking for %s... ' % name )
     ret = context.TryAction('pkg-config --exists \'%s\'' % name)[0]
     context.Result( ret )
     return ret

# Configuration:

conf = Configure(env, custom_tests = { 'CheckPKGConfig' : CheckPKGConfig,
                                       'CheckPKG' : CheckPKG })

#if not conf.CheckPKGConfig('0.15.0'):
#     print 'pkg-config >= 0.15.0 not found.'
#     Exit(1)

#if not conf.CheckPKG('GTK+-2.0 >= 2.4.9'):
#     print 'GTK+-2.0 >= 2.4.9 not found.'
#     Exit(1)

env = conf.Finish()

env.ParseConfig('pkg-config --cflags --libs libxul')
env.SharedObject(target="src/common/np_entry.o", source="src/common/np_entry.cpp")
env.SharedObject(target="src/common/npn_gate.o", source="src/common/npn_gate.cpp")
env.SharedObject(target="src/common/npp_gate.o", source="src/common/npp_gate.cpp")

envPyp = env.Clone()
envPyp.ParseConfig("python-config --cflags")
envPyp.ParseConfig("python-config --ldflags")
envPyp.ParseConfig("pkg-config gtk+-2.0 --cflags --libs")

envPyp.SharedObject(target="src/pypplets/pypplets.o", source="src/pypplets/pypplets.cpp")
#envPyp.SharedObject(["src/pypplets/plugin.cpp"])
envPyp.SharedObject(target="src/pypplets/plugin.o", source="src/pypplets/plugin.cpp")
envPyp.SharedLibrary('pypplets', ["src/pypplets/plugin.o", "src/pypplets/pypplets.o", "src/common/np_entry.o", "src/common/npn_gate.o", "src/common/npp_gate.o"])

